// pages/sloper/sloper.js
Page({
  data: {
    slope: 0
  },
  accelerometerChangeFn(res) {
    var y = res.y
    var z = res.z
    var slope = Math.atan(y / z) * 180 / Math.PI
    slope = Math.round(slope)
    this.setData({
      slope: slope
    })
  },
  onShow() {
    wx.startAccelerometer({
      interval: 'game'
    }).then(res => {
      wx.onAccelerometerChange(this.accelerometerChangeFn)
    })
  },
  onHide() {
    wx.offAccelerometerChange()
    wx.stopAccelerometer()
  }
})